package com.ruoyi.web.controller.wechatApplet;

import com.ruoyi.background.domain.AppWorkTeam;
import com.ruoyi.background.domain.AppWorkTeamUser;
import com.ruoyi.background.service.IAppWorkTeamService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/wechat/workTeam")
public class WorkTeamController extends BaseController {


    @Autowired
    private IAppWorkTeamService workTeamService;

    /**
     * 用户创建队伍
     *
     * @param name 队伍的名称
     * @return 结果
     */
    @GetMapping("/createTeam/{name}")
    public AjaxResult createTeam(@PathVariable String name) {
        AppWorkTeam appWorkTeam = new AppWorkTeam();
        appWorkTeam.setName(name);
        return toAjax(workTeamService.insertAppWorkTeam(appWorkTeam));
    }

    /**
     * 用户加入队伍
     *
     * @param teamCode 队伍编码
     * @return 结果
     */
    @GetMapping("/joinTeam/{teamCode}")
    public AjaxResult userJoinTeam(@PathVariable String teamCode) {
        return toAjax(workTeamService.userJoinTeam(teamCode));
    }

    /**
     * 获取用户队伍的信息
     *
     * @return 结果
     */
    @GetMapping("/getUserTeamInfo")
    public AjaxResult getUserTeamInfo() {
        AppWorkTeamUser userTeamInfo = workTeamService.getUserTeamInfo();
        if (ObjectUtils.isEmpty(userTeamInfo))
            userTeamInfo = new AppWorkTeamUser();
        return AjaxResult.success(userTeamInfo);

    }


}
